package com.example.langchain4j_springboot.controller;

import com.example.langchain4j_springboot.Service.Assistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/rag")
@RequiredArgsConstructor
public class RagDemo01Controller {
    public final Assistant assistant;
    final EmbeddingStore<TextSegment> embeddingStore;

    @RequestMapping("/demo01")
    public String demo01(String message) {
        return assistant.Chat(message);
    }
    @RequestMapping("/demo01Result")
    public String demo01Result(String message) {
        List<Document> documents = FileSystemDocumentLoader
                .loadDocuments("C:\\Users\\Administrator\\Desktop\\001");
           EmbeddingStoreIngestor.ingest(documents, embeddingStore);
            return "成功";
    }
}
